
@extends('admin.common.base-master')
<link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@section('html-head')


@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.addressInfoList')}}">地址列表</a>
        </div>

        @include("admin.common.banner-header")
        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.addressSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>id</th>
                    <th>省份/直辖市</th>
                    <th>城市</th>
                    <th>地区</th>
                    <th>镇</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($addresses) > 0)
                    @foreach($addresses as $address )
                        @if(!is_null($address->area))
                        <tr id="address_{{$address ->id}}">
                            <td>{{$address->id}}</td>
                            <td>{{$address->province}}</td>
                            <td>{{$address->city}}</td>
                            <td>{{$address->area}}</td>
                            <td>{{$address->town}}</td>
                            <td>
                                @if(!is_null($address->town))
                                <a class="color2" href="{{route("Admin.Home.addressSet")}}?id={{$address->id}}">编辑</a>
                                <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$address->id}}">删除 </a>
                                    @else
                                    <span style="color: #c5c8c0">不可操作</span>
                                @endif
                            </td>
                        </tr>
                        @endif
                    @endforeach
                @endif
                </tbody>
            </table>
            <div class="pagelist" style="text-align: center;">
                <?php echo $addresses->render(); ?>
            </div>
        </div>

    </div>

    <script>
        $(document).on("click",".del",function(){
            var id = $(this).attr("data-id");

            noty({
                text: '你确定要删除吗?',
                buttons: [
                    {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delAddress')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#address_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                    },
                    {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                    }
                ]
            });

        });


    </script>
@endsection
